package zwp.example.demo1.demo_controller;

import io.swagger.annotations.Api;
import jakarta.annotation.Resource;
import lombok.RequiredArgsConstructor;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.core.ValueOperations;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import zwp.example.demo1.demo_pojo.dto.DtoTest1;
import zwp.example.demo1.demo_pojo.vo.VoTest1;

import java.time.LocalDate;
import java.util.Map;
import java.util.Optional;

/**
 * @author zwp14
 */
@RestController
@RequestMapping("/zwp")
@Api(tags = "测试类")
@RequiredArgsConstructor
public class DemoRedisTemplateMapController {


//    private final StringRedisTemplate redisTemplate;
    @Resource(name = "databaseRedisTemplateMap")
    private final Map<Integer,RedisTemplate<Object,Object>> templateMap;

    @PostMapping("/test1")
    public VoTest1 test1(@RequestBody DtoTest1 dtoTest1){
        LocalDate time = dtoTest1.getTime();
        System.out.println(time);
        String s = time.toString();
        VoTest1 voTest1 = new VoTest1();
        voTest1.setString(s);
        return voTest1;
    }

//    @PostMapping("/test2")
//    public void test2(){
//        ValueOperations<Object,Object> valueOperations = template.opsForValue();
//        valueOperations.set("1","test1");
////        SetOperations<String, String> stringStringSetOperations = redisTemplate.opsForSet();
////        stringStringSetOperations.add("1","test2");
//    }

    @PostMapping("/test3")
    public void test3(){
        RedisTemplate<Object, Object> redisTemplate = templateMap.get(1);
        ValueOperations<Object, Object> objectObjectValueOperations = redisTemplate.opsForValue();
        objectObjectValueOperations.set("1","firstJAVA");
        Object o = objectObjectValueOperations.get("1");
        Optional<Object> o1 = Optional.ofNullable(o);
        Object value = o1.orElse("Value is null");
        System.out.println(value);
    }
}
